﻿using System.Web.Mvc;
using Hk.Core;
using Hk.Core.General;
using Hk.Core.Services;

namespace Hk.Biker.Controllers
{
    public class WebsiteController : Controller
    {
        private readonly Post _postService;
        private readonly Terms _termsService;

        public WebsiteController()
        {
            _postService = new Post();
            _termsService = new Terms();
        }


        public ActionResult Index(int p = 1)
        {
            ViewBag.Meta = GenerateMeta.AutoGenerateMeta("home", "");
            var products = _postService.GetAllPostHomePage(p, 20);
            var url = Request.RawUrl.Split('?')[0];
            var pagination = _postService.GetPaginationHomePage(p, 3, 20, "", url);
            var service = new CategoryService()
            {
                ListPost = products,
                Pagination = pagination
            };
            return View(service);
        }

        public ActionResult Product(string alias)
        {
            ViewBag.Meta = GenerateMeta.AutoGenerateMeta("detail", alias);
            var detail = _postService.GetByAlias(alias);
            return View(detail);
            
        }

        public ActionResult Category(string alias, int p = 1)
        {
            ViewBag.Meta = GenerateMeta.AutoGenerateMeta("category", alias);
            var term = _termsService.GetByAlias(alias);
            var products = _postService.GetPostByCategory(p, 20, alias);
            var url = Request.RawUrl.Split('?')[0];
            var pagination = _postService.GetPaginationByCategory(p, 3, 20, "", url, alias);
            var service = new CategoryService()
            {
                Term = term,
                ListPost = products,
                Pagination = pagination
            };
            return View(service);
        }

        public ActionResult Sizing()
        {
            return View();
        }

        public ActionResult TrackOrder()
        {
            return View();
        }

        public ActionResult Contact()
        {
            return View();
        }

        public ActionResult Cart()
        {
            return View();
        }

        [HttpPost]
        public ActionResult SendContact(string name, string email, string address, string message)
        {
            var str = "<div><strong>Name</strong>: " + name + "<br /><strong>Email</strong>: " + email
                + "<br /><strong>Address</strong>: " + address + "</div>"
                + "<br /><strong>Content</strong>: " + message + "</div>";
            Email.SendMail("Thư liên hệ từ : " + name + " - " + Request.Url.Host, str);
            return Redirect("/contact/?msg=true");
        }
    }
}
